package com.xuecheng.content.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xuecheng.api.content.model.dto.TeachplanMediaDTO;
import com.xuecheng.api.content.model.qo.QueryTeachplanMediaModel;
import com.xuecheng.common.domain.code.CommonErrorCode;
import com.xuecheng.common.domain.response.RestResponse;
import com.xuecheng.common.exception.ExceptionCast;
import com.xuecheng.content.agent.MediaApiAgent;
import com.xuecheng.content.entity.TeachplanMedia;
import com.xuecheng.content.mapper.TeachplanMediaMapper;
import com.xuecheng.content.service.TeachplanMediaService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author itcast
 */
@Slf4j
@Service
public class TeachplanMediaServiceImpl extends ServiceImpl<TeachplanMediaMapper, TeachplanMedia> implements TeachplanMediaService {

    @Override
    public RestResponse<Integer> getTeacherMediaCount(Long mediaId) {
        boolean empty = ObjectUtils.isEmpty(mediaId);
        if(empty){
//            ExceptionCast.cast(CommonErrorCode.E_100106);
            RestResponse.validfail(CommonErrorCode.E_100106);
        }
        LambdaQueryWrapper<TeachplanMedia> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(TeachplanMedia::getMediaId,mediaId);
        int count = this.count(queryWrapper);
        return RestResponse.success(count) ;
    }
}
